package com.hzcc.hzccblog.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Author 早睡蛋
 * @Date 2022/6/6 16:26:30
 * @Desc:Swagger2配置类
 */

@Configuration
@EnableSwagger2
@EnableKnife4j
public class Swagger2Config {

    @Bean
    public Docket adminApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("管理员API")
                .apiInfo(adminApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/api/admin/.*")))
                .build();
    }
    private ApiInfo adminApiInfo(){
        return new ApiInfoBuilder()
                .title("管理员-API文档")
                .description("本文档描述了管理员相关接口定义")
                .version("1.0")
                .contact(new Contact("早睡蛋", "http://www.hezc.top", "858162638@qq.com"))
                .build();
    }

    @Bean
    public Docket articleApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("文章API")
                .apiInfo(articleApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/api/article/.*")))
                .build();
    }
    private ApiInfo articleApiInfo(){
        return new ApiInfoBuilder()
                .title("文章-API文档")
                .description("本文档描述了学生相关接口定义")
                .version("1.0")
                .contact(new Contact("早睡蛋", "http://www.hezc.top", "858162638@qq.com"))
                .build();
    }

    private ApiInfo testApiInfo(){
        return new ApiInfoBuilder()
                .title("测试-API文档")
                .description("本文档描述了测试相关接口定义")
                .version("1.0")
                .contact(new Contact("早睡蛋", "http://www.hezc.top", "858162638@qq.com"))
                .build();
    }
    @Bean
    public Docket testApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("测试API")
                .apiInfo(testApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/api/test/.*")))
                .build();
    }

    private ApiInfo loginApiInfo(){
        return new ApiInfoBuilder()
                .title("测试-API文档")
                .description("本文档描述了测试相关接口定义")
                .version("1.0")
                .contact(new Contact("早睡蛋", "http://www.hezc.top", "858162638@qq.com"))
                .build();
    }
    @Bean
    public Docket loginApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("登录注册API")
                .apiInfo(loginApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/api/login/.*")))
                .build();
    }
}
